<?php
/**
 * Description: 开屏页面和插图接口
 * User: lizhen
 * Date: 16/9/23
 * Time: 11:49
 */

class GetPromoteFlash implements iController
{
    const PROMOTE_FLASH_TYPE_DAILYPLAN  = 'dailyplan';
    const PROMOTE_FLASH_TYPE_DAILYLEARN = 'dailylearn';
    const PROMOTE_FLASH_TYPE_QUIZBANK   = 'quizbank';

    public function output($queryArgs)
    {
        global $cmsdb;

        if (empty($queryArgs['app_type']))
            return genOutput(1000);

        switch ($queryArgs['app_type']) {

            case self::PROMOTE_FLASH_TYPE_DAILYPLAN:
                $optionName = 'promote_flash_dailyplan';
                break;

            case self::PROMOTE_FLASH_TYPE_DAILYLEARN:
                $optionName = 'promote_flash_dailylearn';
                break;

            case self::PROMOTE_FLASH_TYPE_QUIZBANK:
                $optionName = 'promote_flash_quizbank';
                break;

            default:
                return genOutput(1000);
        }

        $optionsInfo = $cmsdb->getRow("select * from wp_options where option_name = '{$optionName}' ");
        if (empty($optionsInfo))
            return genOutput(1000);

        $optionValue = unserialize($optionsInfo->option_value);

        foreach ($optionValue as $k => $v) {
            $optionValue[$k]['enable'] = $v['enable'] == 1 ? true : false ;
            //如果时间已过期 设置为false
            if (strtotime($v['deadline']) <= time())
                $optionValue[$k]['enable'] = false;

            unset($optionValue[$k]['deadline']);
        }

        return genOutput( 1,array(
            'response_code' => 1,
            'image' => $optionValue['image'],
            'alert' => $optionValue['alert']
        ));
    }

}